﻿<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
	private string _lang;
	protected void Page_Load(object sender, EventArgs e)
	{
		_lang = null;
		string parLang = Request.Params["lang"];
		if(parLang != null) {
			if(parLang.ToLower() == "cz") {
				_lang = "cz";
			} else if(parLang.ToLower() == "en") {
				_lang = "en";
			}
		}
		if(!IsPostBack) {
			if(_lang == "cz" || (string.IsNullOrEmpty(_lang) && System.Threading.Thread.CurrentThread.CurrentCulture.Name == "cs-CZ")) {
				comLanguage.SelectedIndex = 1;
				//tbLanguage.Text = "Jazyk";
				tbDelay.Text = "Simulace zpoždění linky [ms]";
			} else {
				comLanguage.SelectedIndex = 0;
				//tbLanguage.Text = "Language";
				tbDelay.Text = "Line delay [ms]";
			}
		}
		// delay
    if(!Page.IsPostBack) {
      string sdelay = (string)System.Web.HttpContext.Current.Session["servicedelay"];
      if(!string.IsNullOrEmpty(sdelay)) {
        int delay;
        int.TryParse(sdelay, out delay);
        if(delay > 0) txtDelay.Text = delay.ToString(); else txtDelay.Text = "";
      }
    }
	}

	public string GetLanguage()
	{

		return ((comLanguage.SelectedIndex == 1) ? "cs-CZ" : "en-US");
	}

	protected void comLanguage_SelectedIndexChanged(object sender, EventArgs e)
	{
		Response.Redirect("DataGridToolBar.aspx?lang=" + comLanguage.SelectedValue);
	}
	protected void SetDelay_Click(object sender, EventArgs e)
	{
		int delay;
		int.TryParse(txtDelay.Text, out delay);
		if(delay != 0) {
			if(delay > 5000) delay = 5000;
			txtDelay.Text = delay.ToString();
			Session["servicedelay"] = delay.ToString();
		} else {
			txtDelay.Text = "";
			Session["servicedelay"] = "0";
		}
	}

</script>


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Demo DataGridToolbar</title>
		<style type="text/css">
    html, body {
	    height: 100%;
	    overflow: auto;
    }
    body {
	    padding: 0;
	    margin: 0;
    }
    #silverlightControlHost {
	    height: 100%;
	    text-align:center;
    }
    #updPanelSetup
    {
    	display:inline;
    }
    </style>
    <script type="text/javascript" src="Silverlight.js"></script>
    <script type="text/javascript">
    	function onSilverlightError(sender, args) {
    		var appSource = "";
    		if (sender != null && sender != 0) {
    			appSource = sender.getHost().Source;
    		}

    		var errorType = args.ErrorType;
    		var iErrorCode = args.ErrorCode;

    		if (errorType == "ImageError" || errorType == "MediaError") {
    			return;
    		}

    		var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n";

    		errMsg += "Code: " + iErrorCode + "    \n";
    		errMsg += "Category: " + errorType + "       \n";
    		errMsg += "Message: " + args.ErrorMessage + "     \n";

    		if (errorType == "ParserError") {
    			errMsg += "File: " + args.xamlFile + "     \n";
    			errMsg += "Line: " + args.lineNumber + "     \n";
    			errMsg += "Position: " + args.charPosition + "     \n";
    		}
    		else if (errorType == "RuntimeError") {
    			if (args.lineNumber != 0) {
    				errMsg += "Line: " + args.lineNumber + "     \n";
    				errMsg += "Position: " + args.charPosition + "     \n";
    			}
    			errMsg += "MethodName: " + args.methodName + "     \n";
    		}

    		throw new Error(errMsg);
    	}
    </script>
</head>
<body>

    <form id="form1" runat="server" style="height:100%">
		<asp:ScriptManager ID="sm11" runat="server">
		</asp:ScriptManager>
    <div style="vertical-align:middle; padding:10px 0 15px 30px" >
			 <asp:Label id="tbLanguage" Text="Language<br/>Jazyk" runat="server"></asp:Label>
       	 &nbsp;<asp:DropDownList runat="server" id="comLanguage" AutoPostBack="True" 
				 Width="87px" onselectedindexchanged="comLanguage_SelectedIndexChanged">
				 <asp:ListItem>EN</asp:ListItem>
				 <asp:ListItem>CZ</asp:ListItem>
			 </asp:DropDownList>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<asp:UpdatePanel ID="updPanelSetup" runat="server" >
				<ContentTemplate>
					 <asp:Label id="tbDelay" Text="Simulace zpoždění linky [ms]" runat="server"></asp:Label>
					 &nbsp;
					 <asp:TextBox runat="server" id="txtDelay" Width="50pt" EnableTheming="False" 
						 EnableViewState="false" ></asp:TextBox>
					 &nbsp;
					 <asp:Button  runat="server" Text="Set" onclick="SetDelay_Click" />
				 </ContentTemplate>
			</asp:UpdatePanel>

    </div>
		    <div id="silverlightControlHost">
        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
		  <param name="source" value="ClientBin/DemoDataGridToolBar.xap"/>
		  <param name="onError" value="onSilverlightError" />
		  <param name="background" value="white" />
		  <param name="minRuntimeVersion" value="4.0.50401.0" />
		  <param name="autoUpgrade" value="true" />
			<param name="culture" value="<%=GetLanguage()%>"/>   
			<param name="uiculture" value="<%=GetLanguage()%>"/>
		  <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.0" style="text-decoration:none">
 			  <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
		  </a>
	    </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe>
			</div>
    </form>
</body>
</html>
